#!/bin/bash
#

#####练习

#判断位置参数是否和规
if [ $# -eq 0 ];then
    echo "$0 < 1.系统名练习,2.用户练习,3.查看数据库线程状态"
    exit 88
fi

case $1 in
1)
    echo "====系统名练习====" 
    read -p "请输入系统名称: " A
    XT=`echo "$A" | tr 'A-Z' 'a-z'`

    if [ "$XT" == linux ];then
        echo "===>红帽"
    elif [ "$XT" == windows ];then
        echo "===>微软"
    elif [ "$XT" == mac ];then
        echo "===>苹果"
    else
        echo "===>其他"
    fi
;;
2)   
    echo "====用户练习===="
    read -p "请输入需要查找的用户名: " user_name
    id $user_name &> /dev/null
    if [ "$?" -eq 0 ]; then
	uid=`id -u $user_name`
	gid=`id -g $user_name`
	
	if [ "$uid" == "$gid" ];then
	    echo "===>GOOD"
	else
	    echo "===>BAD"
	fi
    else
	echo "[error] >>用户${user_name}不存在"
    fi
;;
3)
    echo "====查看数据库线程状态===="
    username=root
    password=WWW.1.com
    
    ZT1=`mysql -u$username -p$password -e "show slave status\G" 2> /dev/null |grep -w "Slave_SQL_Running"|awk '{print $2}'`    
    ZT2=`mysql -u$username -p$password -e "show slave status\G" 2> /dev/null |grep -w "Slave_IO_Running"|awk '{print $2}'`    
    if [ "$ZT1" == "Yes" -a "$ZT2" == "Yes" ];then
        echo "1"
    else
        echo "0"
    fi
;;
4)
    echo "测试"
    if [ "$1" == "4" ]
    then
        echo "111"
    fi
;;
*)
    echo "[error] >>参数不正确"
;;
esac
